(function($) {
    $.extend({
        checkNull:function(value) {
            if(value==null||value==""||value=="undefined"||value=="null"){
                return false;
            }
            return true;
        },
        queryCode:function(selector,codeType,checkedValue) {
            //$.configSelector();
            selector.empty();
            //selector.chosen("destroy");
            $.ajax({
                url: getRootPath()+"/syscode/queryList?codeType="+codeType,
                type: 'get',
                success: function (data) {
                    console.log(data);
                    if (data.length != 0) {
                        selector.append("<option value=''>请选择</option>");
                        $.each(data, function (i) {
                            if ($.checkNull(checkedValue) && checkedValue == data[i].codeValue) {
                                selector.append("<option value='" + data[i].codeValue + "' selected='selected'>" + data[i].codeName + "</option>");
                            } else {
                                selector.append("<option value='" + data[i].codeValue + "'>" + data[i].codeName + "</option>");
                            }

                        });
                        //selector.chosen({width: "30%", disable_search: true});
                    } else {
                        console.log('未查询到下拉列表代码！');
                    }
                },
                error: function (err) {
                    console.log('初始化下拉列表失败！');
                }
            });
        }
    });
})(jQuery);

function getRootPath(){
    var strFullPath=window.document.location.href;
    console.log(strFullPath);
    var strPath=window.document.location.pathname;
    console.log(strPath)
    var pos=strFullPath.indexOf(strPath);
    var prePath=strFullPath.substring(0,pos);
    console.log(prePath)
    //return prePath;
    return "";
}

function showTips(type,content){
	var html = "<div class='ui-poptips ui-poptips-"+ type + "' id='tipsDiv' style='display: none'>";
	html += "<div class='ui-poptips-cnt'><i></i> " + content + "</div></div>";
	$("body").append(html);
	$("#tipsDiv").fadeIn("slow",function(){
		$("#tipsDiv").fadeOut("slow",function(){
			$(".ui-poptips").each(function(){
				$(this).remove();
			});
		});
	});
}

function getNoMoreDataDiv() {
    var html = "<div style='text-align: center;color: #777' class='nodata-div'>没有更多数据了</div>";
    return html;
}

/*
function getLoadingDiv() {
    var html = "<div style='text-align: center;color: #777' class='loading-div'>加载中。。。</div>";
    return html;
}

function removeLoadingDiv() {
    $(".loading-div").remove();
}
*/

function getLoadingDiv() {
    var html = "<div style='text-align: center;color: #777' class='ui-loading-wrap'><p>正在加载中...</p><i class='ui-loading'></i></div>";
    return html;
}

function removeLoadingDiv() {
    $(".ui-loading-wrap").remove();
}


Date.prototype.format = function(format) {
       var date = {
              "M+": this.getMonth() + 1,
              "d+": this.getDate(),
              "h+": this.getHours(),
              "m+": this.getMinutes(),
              "s+": this.getSeconds(),
              "q+": Math.floor((this.getMonth() + 3) / 3),
              "S+": this.getMilliseconds()
       };
       if (/(y+)/i.test(format)) {
              format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
       }
       for (var k in date) {
              if (new RegExp("(" + k + ")").test(format)) {
                     format = format.replace(RegExp.$1, RegExp.$1.length == 1
                            ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
              }
       }
       return format;
};

Number.prototype.toDateString = function(){
	var date = new Date();
	date.setTime(this);
	return date.format('yyyy-MM-dd h:m:s');
};

Number.prototype.toFloat = function(decimal){
	var f = parseFloat(this);    
    if (isNaN(f)) {    
        return false;    
    }    
    var f = Math.round(this*100)/100;    
    var s = f.toString();    
    var rs = s.indexOf('.');    
    if (rs < 0) {    
        rs = s.length;    
        s += '.';    
    }    
    while (s.length <= rs + 2) {    
        s += '0';    
    }    
    return s;    
};



/**
 * null 返回true，否则返回false
 * 
 * @param value
 * @returns {Boolean}
 */
function isNull(value) {
	if(value==null||value==""||value=="undefined"||value=="null"){
		return true;
	}
	return false;
}

function isPhoneNo(phone){
	
	 if(!(/^1\d{10}$/.test(phone))){
		 
		 return false;
	 }
	 return true;
}
